<%@ page import="com.jspsmart.upload.SmartUpload" %>
<%@ page import="com.jspsmart.upload.Request" %>
<%@ page import="entity.AdminMan" %>
<%@ page import="entity.UsNews" %>
<%@ page import="entity.Board" %>
<%@ page import="dao.IUsNewsDao" %>
<%@ page import="Impl.UsNewsDaoImpl" %><%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2019/4/3
  Time: 18:26
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<%
    request.setCharacterEncoding("UTF-8");
    response.setCharacterEncoding("UTF-8");
    SmartUpload sm=new SmartUpload();
    sm.initialize(pageContext);
    sm.setCharset("UTF-8");
    sm.upload();
    sm.save("upfiles");
    Request srt=sm.getRequest();
    String title =srt.getParameter("title");
    String context=srt.getParameter("context");
    String pic=sm.getFiles().getFile(0).getFileName();
    int boardId= Integer.parseInt(srt.getParameter("boardid"));
    AdminMan ad= (AdminMan) session.getAttribute("am");
    UsNews uns=new UsNews(title,context,pic,new Board(boardId),ad,1);
    IUsNewsDao iud=new UsNewsDaoImpl();
    int b=iud.addNews(uns);
    if (b>0){
        request.getRequestDispatcher("show_news.jsp").forward(request,response);
    }else {
        out.print("<script>alert('添加失败');</script>");
    }
%>

</body>
</html>
